﻿package frEngine.shader.filters.fragmentFilters.extra
{
    import __AS3__.vec.*;
    import baseEngine.core.*;
    import com.gengine.resource.*;
    import frEngine.*;
    import frEngine.shader.*;
    import frEngine.shader.filters.*;
    import frEngine.shader.registType.*;

    public class SecondRollTextureFilter extends FilterBase
    {
        public var texture:Texture3D;
        public var uvRollValue:Vector.<Number>;
        public var Uspeed:Number = 0;
        public var Vspeed:Number = 0;
        private var _lastTickTime:Number;

        public function SecondRollTextureFilter(param1:Texture3D)
        {
            this.uvRollValue = this.Vector.<Number>([0, 0, 0, 0]);
            super(FilterType.SecondRollTextureFilter, FilterPriority.SecondRollTexture, [param1]);
            this._lastTickTime = TimeControler.stageTime;
            this.texture = param1;
            return;
        }// end function

        public function set lightStrength(param1:Number) : void
        {
            this.uvRollValue[3] = param1;
            return;
        }// end function

        override public function setRegisterParams(param1:Program3dRegisterInstance) : void
        {
            param1.getParamByName("{TextureRoll}", false).value = this.uvRollValue;
            param1.getParamByName("{SecRollTexture}", false).value = this.texture;
            return;
        }// end function

        override public function get programeId() : String
        {
            if (this.texture && (this.texture.loadedAndUpload || this.texture.targetInfo))
            {
                return "SecondRoll " + FilterBase.ATLFormat[this.texture.format] + ",mip:" + this.texture.mipMode;
            }
            return null;
        }// end function

        override public function createFragmentUvCoord(param1:Program3dRegisterInstance) : String
        {
            var _loc_4:Array = null;
            var _loc_5:String = null;
            var _loc_2:String = "";
            var _loc_3:* = param1.getParamByName(FilterName.F_UVPostion, false);
            if (_loc_3)
            {
                _loc_4 = new Array();
                _loc_5 = _loc_3.paramName;
                _loc_4.push(new ToBuilderInfo("fc0", "{TextureRoll}", false, 1, this.uvRollValue));
                _loc_4.push(new ToBuilderInfo("ft0", "{UV2}", false, 1));
                _loc_2 = _loc_2 + ("mov           {UV2}.xy        " + _loc_5 + ".xy          \t\n");
                _loc_2 = _loc_2 + "add           {UV2}.xy        {UV2}.xy      {TextureRoll}.xy    \t\n";
                _loc_2 = param1.toBuild(_loc_2, _loc_4);
            }
            return _loc_2;
        }// end function

        override public function createFragmentColor(param1:Program3dRegisterInstance, param2:Boolean) : String
        {
            var _loc_3:* = param1.getParamByName(FilterName.F_UVPostion, false);
            if (!_loc_3)
            {
                return "";
            }
            var _loc_4:* = new Array();
            _loc_4.push(new ToBuilderInfo("fs0", "{SecRollTexture}", false, 1, this.texture));
            var _loc_5:String = "";
            _loc_5 = _loc_5 + ("tex        ft0           {UV2}.xy    " + getSmapleString("fs0", this.texture.format, true, this.texture.mipMode) + "\t\n");
            if (this.texture.format == TextureFormat.FORMAT_COMPRESSED_ALPHA)
            {
                _loc_5 = _loc_5 + "mul\t\t\tft0.xyz\t   ft0.xyz\t\t\tft0.w\t \t\t\t\n";
            }
            _loc_5 = _loc_5 + "mul        ft0.xyz       ft0.xyz \t\t{output}.w\t\t\t\t\n";
            _loc_5 = _loc_5 + "mul        ft0.xyz       ft0.xyz \t\t{TextureRoll}.w\t\t\t\t\n";
            _loc_5 = _loc_5 + "add       {output}.xyz   {output}.xyz   ft0.xyz \t\t\t\t\n";
            _loc_5 = param1.toBuild(_loc_5, _loc_4);
            return _loc_5;
        }// end function

        override public function update() : void
        {
            var _loc_1:* = TimeControler.stageTime;
            var _loc_2:* = _loc_1 - this._lastTickTime;
            this._lastTickTime = _loc_1;
            this.uvRollValue[0] = this.uvRollValue[0] + _loc_2 * this.Uspeed / 10000;
            this.uvRollValue[1] = this.uvRollValue[1] + _loc_2 * this.Vspeed / 10000;
            return;
        }// end function

    }
}
